import Big from 'big.js'

// 科学计数-绝对值
export function BigAbs(num1: number) {
  return new Big(num1).abs().toNumber()
}
// 科学计数-加
export function BigPlus(num1: number, num2: number) {
  let num11 = new Big(num1), num22 = new Big(num2);
  const num = new Big(num11.plus(num22))
  return num.round(4).toNumber()
}
// 科学计数-减
export function BigMinus(num1: any, num2: any) {
  let num11 = new Big(num1), num22 = new Big(num2);
  const num = new Big(num11.minus(num22))
  return num.round(4).toNumber()
}
// 科学计数-乘
export function BigTimes(num1: number, num2: number) {
  if (!num1 || !num2) return 0
  let num11 = new Big(num1), num22 = new Big(num2)
  const num = new Big(num11.times(num22))
  return num.round(4).toNumber()
}
// 科学计数-除
export function BigDiv(num1: number, num2: number) {
  if (!num1 || !num2) return 0
  let num11 = new Big(num1), num22 = new Big(num2)
  const num = new Big(num11.div(num22))
  return num.round(4).toNumber()
}
// 金额-除10000
export function BigWan(num1: any) {
  if (!num1) return 0
  let num11 = new Big(num1), num22 = new Big(10000);
  const num = new Big(num11.div(num22))
  return num.round(4).toNumber()
}
// 金额-乘10000
export function BigTimeWan(num1: any) {
  if (!num1) return 0
  let num11 = new Big(num1),
    num22 = new Big(10000)
  const num = new Big(num11.times(num22))
  return num.round(4).toNumber()
}
// 概率-除100
export function BigHundred(num1: any) {
  if (!num1) return 0
  let num11 = new Big(num1),
    num22 = new Big(100)
  const num = new Big(num11.div(num22))
  return num.round(4).toNumber()
}
// 概率-乘100
export function BigTimeHundred(num1: any) {
  if (!num1) return 0
  let num11 = new Big(num1),num22 = new Big(100);
  const num = new Big(num11.times(num22))
  return num.round(4).toNumber()
}

// 保留两位小数
export function BigTofixedTwo(num: number) {
  if (!num) return 0
  if (num > 0) {
    return Math.floor(num * 100) / 100
  } else {
    return Math.ceil(num * 100) / 100
  }
}
// 保留整数
export function BigInteger(num: number) {
  if (!num ) return 0
  let num1 = new Big(num).round(0,Big.roundDown);
  return num1
}
// 科学计数-计算百分比
export function BigPercent(num1: number, num2: number) {
  if (!num1 || !num2) return 0
  let num11 = new Big(num1), num22 = new Big(num2);
  const num = new Big(num11.div(num22)).round(2).toNumber()
  const percent = new Big(new Big(num).times(100))
  return percent + '%'
}
// 科学计数-数值效果(保留4位小数)
export function BigNumericalEffect(num1: number, num2: number) {
  if (!num1 || !num2) return 0
  let num11 = new Big(num1), num22 = new Big(num2);
  const num = new Big(num11.div(num22)).round(4).toNumber()
  const percent = new Big(new Big(num).times(100))
  return percent + '%'
}
//为了能排序
export function BigPercentNumber(num1: number, num2: number) { 
  if (!num1 || !num2) return 0
  let num11 = new Big(num1), num22 = new Big(num2);
  const num = new Big(num11.div(num22)).round(4).toNumber()
  const percent = new Big(new Big(num).times(100))
  return percent
}

// rpt = 总赢 / 总下注 * 100%(保留两位)
export function RtpPercent(num1: number, num2: number) {
  if (!num1 || !num2) return 0
  let num11 = new Big(num1), num22 = new Big(num2);
  const num = new Big(num11.div(num22)).round(4).toNumber()
  const percent = new Big(new Big(num).times(100))
  return percent + '%'
}

// 计算盈利率  投注 / 返奖  - 100%(保留两位小数)
export function EarningPercent(num1:number,num2:number) {
  if (!num1 || !num2) return 0
  let num:number = num1 / num2 * 100 - 100;
  let str = 0;
  if (num > 0) {
    str = Math.floor(num * 100) / 100
  } else {
    str = Math.ceil(num * 100) / 100
  }
  return str
}
// 计算盈利率环比
export function EarningPercentRadio(num1:number,num2:number) {
  if (!num1 || !num2) return 0
  let num:number = num1 / num2 * 100;
  let str = 0;
  if (num > 0) {
    str = Math.floor(num * 100) / 100
  } else {
    str = Math.ceil(num * 100) / 100
  }
  return str
}